<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>角色管理 </title>
	<#include '/commons/include/head.ftl'>
</head>

<body>

	<div id="dg">
		<div id="toolbars" style="display:none;">
			<form id="searchForm">
				<div class="datagrid-toolbars">
					<div class="toolbar-row">
						<div class="group">
							<a onclick="form_dialog('add');" href="javascript:;" class="bto bto-green"><i class="fa fa-plus"></i><span>新增</span></a>
							<a onclick="form_dialog('update');" href="javascript:;" class="bto bto-blue"><i class="fa fa-pencil"></i><span>编辑</span></a>
							<a onclick="del();" href="javascript:;" class="bto bto-red"><i class="fa fa-trash"></i><span>删除</span></a>
							<a onclick="reload();" href="javascript:;" class="bto bto-purple1"><i class="fa fa-refresh"></i><span>刷新</span></a>
							<a onclick="distribute_permit_dialog();" href="javascript:;" class="bto bto-blue1"><i class="fa fa-cog"></i><span>分配权限</span></a>
						</div>
						<div class="group">
							<input name="quickSearch" class="easyui-searchbox" data-options="searcher:quickSearch, width: 150, height: 24,prompt: '快速搜索...'" style="line-height: normal;" />
						</div>
						<div class="group">
							<a onclick="searchBox();" href="javascript:;" class="bto bto-purple2"><i class="fa fa-search"></i><span>搜索</span></a>
							<a onclick="searchClear();" href="javascript:;" class="bto bto-warning"><i class="fa fa-undo"></i><span>重置</span></a>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
	
	
	<script>
	var $dg ;
	$(function(){
		$dg = $("#dg").datagrid({
			title: "角色管理",
            url: "${ctx}/manager/system/role/datagrid",
            idField: "id", fit: true, 
            border: false, striped:true, pageSize: 30, pageList: [30,40,50,100,200,500,1000], 
            pagination: true, rownumbers: true, toolbar: "#toolbars", remoteSort: true, 
            sortName: 'sorting', sortOrder: 'asc', queryParams: {},
            frozenColumns: [[
                { field: "ck", checkbox: true },
                { field: "id", title: "ID", width: 80, sortable: true, hidden: true }
            ]],
            columns: [[ 
                { field: "name", title: "名称", width: 120 },
                { field: "identity", title: "权限标识", width: 120 },
                { field: "description", title: "描述", width: 250 },
                { field: "sorting", title: "排序", width: 50, align: "center", sortable: true },
                { field: "createTime", title: "创建时间", width: 150, sortable: true, align: "center", formatter:function(value,row){
                	return (undefined != value?$.date.format(value, "yyyy-MM-dd HH:mm:ss"):"") ;	
                }},
                { field: "updateTime", title: "修改时间", width: 150, sortable: true, align: "center", formatter:function(value,row){
                	return (undefined != value?$.date.format(value, "yyyy-MM-dd HH:mm:ss"):"") ;	
                }}
            ]],
            onLoadSuccess: function(){
            	$.fn.datagrid.extensions.onLoadSuccess.apply(this, arguments);
            	$dg.datagrid('unselectAll');$dg.datagrid('uncheckAll');$dg.datagrid('clearSelections');
            },
            enableHeaderClickMenu: true, enableHeaderContextMenu: true, enableRowContextMenu: false
        });
	});
	function reload(){$dg.datagrid("reload") ;}
	function quickSearch(value,name){
		var o = {} ; o[name] = value ; $dg.datagrid("load",o);
	}
	function searchBox() {
		var search_form = $.util.serializeObject("#searchForm") ;
		if(search_form.quickSearch === "快速搜索...")search_form["quickSearch"]=null;
		$dg.datagrid("load",search_form);
	}
	function searchClear() {
		$("#searchForm").form("clear") ;
		$dg.datagrid("load",{});
	}
	function getIds() {
		var rows = $dg.datagrid('getChecked');
		var ids = [];
		if (rows.length > 0) {
			for ( var i = 0; i < rows.length; i++) {
				if(undefined != rows[i].id && ""!=rows[i].id) {
					ids.push(rows[i].id);
				}
			}
		}
		return ids ;
	}	
	
	function form_dialog(formType) {
		var form_url = "${ctx}/manager/system/role/form";
		if(formType === "update") {
			var ids = getIds() ;
			if(ids.length == 0) {alertify.warning("请选择一条记录！");return;}
			if(ids.length > 1) {alertify.warning("只能编辑一条记录！");return;}
			form_url = "${ctx}/manager/system/role/form?id="+ids[0];
		}
		
		var $d = $.easyui.showDialog({
			title: "<div class='icon-div'><i class='fa fa-link fa-120 pt-2 fa-c-blue'></i></div> 表单", 
			href: form_url, method: "", 
			iniframe: false, topMost: true, iconCls : "",
			width: 610, height: 344, maximizable: true,
            enableApplyButton: false, enableCloseButton: false, enableSaveButton: false,
            buttons : [ 
              { text : "<i class='fa fa-save fa-120 mt-6 fa-c-green'></i> 应用", handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : "<i class='fa fa-save fa-120 mt-6 fa-c-blue'></i> 保存", handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : "<i class='fa fa-remove fa-120 mt-6 fa-c-red'></i> 关闭", handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function distribute_permit_dialog() {
		var rows = $dg.datagrid('getChecked');
		if(rows.length == 0) {alertify.warning("请选择一条记录！");return;}
		if(rows.length > 1) {alertify.warning("只能编辑一条记录！");return;}
		
		var $d = $.easyui.showDialog({ 
			title: "<div class='icon-div'><i class='fa fa-link fa-120 pt-2 fa-c-blue'></i></div> <font color='red'>["+rows[0].name+"]</font> 分配权限", 
			href: "${ctx}/manager/system/role/role_resource/"+rows[0].id,
			iniframe: false, topMost: true, iconCls : "",
			width: 1040, height: 544, maximizable: true,
            enableApplyButton: false, enableCloseButton: false, enableSaveButton: false,
            buttons : [ 
              { text : "<i class='fa fa-save fa-120 mt-6 fa-c-green'></i> 应用", handler : function() { $.easyui.parent.submitForm($d, $dg, true) ; } },
              { text : "<i class='fa fa-save fa-120 mt-6 fa-c-blue'></i> 保存", handler : function() { $.easyui.parent.submitForm($d, $dg) ; } },
              { text : "<i class='fa fa-remove fa-120 mt-6 fa-c-red'></i> 关闭", handler : function() { $d.dialog('destroy'); } } 
           	]
        });
	}
	
	function del() {
		if(getIds().length == 0) {alertify.warning("请选择一条记录！");return;}
		$.messager.confirm("您确定要进行该操作？", function (c) { 
			if(c) {
				$.easyui.loading({ msg: "数据删除中，请稍等..."});
				deletedAjax("${ctx}/manager/system/role/delete", {"ids" : getIds().join(',')}) ;
			}
		});
	}
	function deletedAjax(url, params) {
		$.post(url, params, function(result) {
			if (result.status) {
				$dg.datagrid("unselectAll");$dg.datagrid("reload") ;
				alertify.success(result.message);
				$.easyui.loaded();
			} else {
				alertify.warning(result.message);
				$.easyui.loaded();
			}
		}, 'json').error(function() { $.easyui.loaded(); });
	}
	</script>
</body>
</html>

